package com.vanke.kotlin.data.server

import com.vanke.kotlin.db.ForecastDb
import com.vanke.kotlin.domain.ForecastDataSource
import com.vanke.kotlin.domain.ForecastList
/**
 * @name Kotlin
 * @package name：com.vanke.kotlin.domain
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/7/27 14:07
 */
class ForecastServer(val dataMapper: ServerDataMapper = ServerDataMapper()
, val  forecastDb: ForecastDb = ForecastDb()) : ForecastDataSource {

    override fun requestForecastByZipCode(zipCode: Long, date: Long): ForecastList? {

        val result = ForecastRequest(zipCode).execute()
        val converted = dataMapper.convertToDomain(zipCode,result)
        forecastDb.saveForecast(converted)
        return forecastDb.requestForecastByZipCode(zipCode,date)
    }

    override fun requestDayForecast(id: Long) = throw UnsupportedOperationException()
}